package com.CollectionJiHe.CollectionAPI;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class Interator_ {
    public static void main(String[] args) {
        Collection<String>c=new ArrayList<>();
        c.add("迪迦");
        c.add("盖亚");
        c.add("戴拿");
        c.add("高斯");
        System.out.println(c);
        //创建一个迭代器对象
        Iterator<String> it = c.iterator();
       while(it.hasNext()){
           String ele=it.next();
           System.out.println(ele);
       }
       //增强for循环来遍历
        for (String s : c) {
            System.out.println(s);

        }
        System.out.println("-----------");
        //使用Lambda表达式来遍历集合
        c.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        c.forEach((String s)->{
            System.out.println(s);
        });
        c.forEach(s->{
            System.out.println(s);
        });
        c.forEach(s-> System.out.println(s) );
        c.forEach(System.out::println );

    }
}
